#include <sys/stat.h>
#include <sys/types.h>

#include<Global.h>
#include<TELFile.h>
#include<TELTrack.h>
#include<TELFileRaw.h>
#include <TelChek.h>

#include<TApplication.h>
#include<TStyle.h>

char CharTmp[20];
char CharTmp2[20];

Int_t RunNumber;

//void menu();


int main(int argc, char* argv[]) {

	TApplication app("myapp", &argc, argv);

	printf("========================================== \n\r");
	printf("=                                        = \n\r");
	printf("=    Reader for silicon MVD telescope    = \n\r");
	printf("=                                        = \n\r");
	printf("========================================== \n\r");
	printf(" R - Convert EUDAQ data to Telana          \n\r");
	printf(" B - Read MVME DAQ data Full               \n\r");
	printf(" N - Pedestal and Threshold                \n\r");
	printf(" > ");

	fgets(CharTmp, 20, stdin);
	CharTmp[0] = toupper(CharTmp[0]);

	printf("Enter number data file: ");
	fgets(CharTmp2, 20, stdin);
	RunNumber = atoi(CharTmp2);

	if (CharTmp[0] == 'N'){
		TELFile ff(RunNumber);
		//ff.PedNoi();
		ff.SimplePedNoi();//Finds pedestal and noise for run without beam
	}
	if (CharTmp[0] == 'B') {
		TELFile ff(RunNumber);
		//ff.SimplePedNoi();//Finds pedestal and noise for run without beam
		//ff.PedNoi();//Finds pedestal and noise
		//ff.FindClusters(3, 3);//Finds clusters and perform prealignment
		//ff.HitNtupl(3, 3);//Builds hit ntuple
		ff.ArtemAligment(3, 3);
		//ff.HitNtuplWithEta(3, 3, 200);//Builds hit ntuple
		//TELTrack track(RunNumber);
		//track.PlotTracks();//Makes info plots for line tracks���� ��
		//TelChek chek(RunNumber);
		//chek.Report(RunNumber);

	}
	if (CharTmp[0] == 'R') {
		TELFileRaw raw(RunNumber);
		raw.OpenFile(RunNumber);
		raw.OpenConvertFile(RunNumber);
		raw.PlugConverter();
		printf("======END===== \n");
	}
	app.Run(true);
}
